package com.example.mobile2021606128wje0415;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

//RecyclerView设备器
//2、适配器继承RecycleView.Adpater,指定范类伟内部类
public class peopleAdapter extends RecyclerView.Adapter<peopleAdapter.ViewHolder>{
    String[] name;

    public peopleAdapter(String[]name){
        this.name=name;

    }


    //1、定义
    TextView tvItemName;
    static class ViewHolder extends RecyclerView.ViewHolder{
        private final TextView tvItemName;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemName=itemView.findViewById(R.id.tv_iterm_name);
        }



    }
//3、添加 父类抽象方法
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.iterm_rv_main_people,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }
//把控件的内容传给适配器
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvItemName.setText(name[position]);

    }

    @Override
    public int getItemCount() {
        return name.length;
    }
}
